import 'package:flutter/material.dart';
import 'package:top_foundation/component/calendar/index.dart';

import '../../../top_foundation.dart';
import '../../../utils/theme/theme.dart';

class CalendarYearView extends StatelessWidget {
  CalendarYearView({Key? key}) : super(key: key);
  final controller = Get.find<CalendarViewController>();
  @override
  Widget build(BuildContext context) {
    return Wrap(
      children: getYears()
          .map(
            (e) => InkWell(
              onTap: () => controller.actionChooseYear(e),
              child: Container(
                width: Get.width / 5,
                height: 42.r,
                margin: EdgeInsets.symmetric(vertical: 5.r),
                alignment: Alignment.center,
                child: Container(
                    width: 42.r,
                    height: 42.r,
                    alignment: Alignment.center,
                    decoration: e == controller.state.curr.value.year
                        ? BoxDecoration(
                            color: ITheme.selectedColor,
                            borderRadius: BorderRadius.circular(20.r))
                        : null,
                    child: Stack(
                      children: [
                        Container(
                          padding: const EdgeInsets.all(2),
                          child: Text(
                            e.toString(),
                            style: TextStyle(
                              color: e == controller.state.curr.value.year
                                  ? Colors.white
                                  : const Color(0xff333333),
                              fontSize: 15.sp,
                            ),
                          ),
                        ),
                        controller.state.curr.value.year == e
                            ? Positioned.fill(
                                bottom: 0,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  crossAxisAlignment: CrossAxisAlignment.end,
                                  children: [
                                    Container(
                                      width: 4,
                                      height: 4,
                                      decoration: BoxDecoration(
                                        color: Colors.blue,
                                        borderRadius: BorderRadius.circular(2),
                                      ),
                                    ),
                                  ],
                                ),
                              )
                            : const SizedBox()
                      ],
                    )),
              ),
            ),
          )
          .toList(),
    );
  }

  List<int> getYears() {
    var curr = controller.state.curr.value.year;
    return List.generate(20, (index) => curr - 10 + index);
  }
}
